import request from '@/utils/request'

// request.get('/db.json').then(
//     response => {
//         console.log(response.data)
//     }
// )

// request({
//     method: 'get',
//     url: '/db.json'
// }).then(
//     response => {
//         console.log(response.data)
//     }
// )

const BASE_URL = '/dev';

export default {
    getList(userName) {
        const req = request({
            method: 'get',
            url: BASE_URL + '/user',
            params: {
                name: userName
            }
        })
        return req;
    },
    deleteUser(id) {
        const req = request({
            method: 'delete',
            url: BASE_URL + '/user',
            params: {
                id: id
            }
            
        })
        return req;
    },

    saveUser(user) {
        const req = request({
            method: 'post',
            url: BASE_URL + '/user',
            data: user
        })
        return req;
    },

    updateUser(user) {
        const req = request({
            method: 'put',
            url: BASE_URL + '/user',
            data: user
        })
        return req;
    },

    updateRole(userId, roleList) {
        const req = request({
            method: 'put',
            url: BASE_URL + '/role/' + userId,
            data: roleList
        })
        return req;
    },

    clearKg() {
        const req = request({
            method: 'delete',
            url: BASE_URL + '/kg',
        })
        return req;
    },

    buildKg(kgTitle, recurrence) {
        const req = request({
            method: 'get',
            url: BASE_URL + '/kg',
            params: {
                title: kgTitle,
                recurr: recurrence
            }
        })
        return req;
    },

    updateSim(sim) {
        const req = request({
            method: 'put',
            url: BASE_URL + '/kg/sim',
            params: {
                similarity: sim
            }
        })
        return req;
    },

    listTitle() {
        const req = request({
            method: 'get',
            url: BASE_URL + '/kg/title',
        })
        return req;
    },

    addTitle(pediaTitle) {
        const req = request({
            method: 'post',
            url: BASE_URL + '/kg/title',
            data: pediaTitle
        })
        return req;
    },

    search(question) {
        const req = request({
            method: 'get',
            url: BASE_URL + '/kg/search',
            params: {
                question: question
            }
        })
        return req;
    },

    deleteTitle(title) {
        const req = request({
            method: 'delete',
            url: BASE_URL + '/kg/title',
            params: {
                title: title
            }
        })
        return req;
    },

    interruptBuild() {
        const req = request({
            method: 'get',
            url: BASE_URL + '/kg/pause'
        })
        return req;
    },

    findWikiTitle(title) {
        const req = request({
            method: 'get',
            url: BASE_URL + '/kg/wikititle',
            params: {
                title: title
            }
        })
        return req;
    },

    listRelatedQuestionByQuestionLike(question) {
        const req = request({
            method: 'get',
            url: BASE_URL + '/rq',
            params: {
                question: question
            }
        })
        return req;
    },

    listAllRelatedQuestions() {
        const req = request({
            method: 'get',
            url: BASE_URL + '/rq',
        })
        return req;
    },

    login(user) {
        const req = request({
            method: 'post',
            url: BASE_URL + '/user/login',
            params: {
                username: user.username,
                password: user.password
            }
        })
        return req;
    },

    logout() {
        const req = request({
            method: 'post',
            url: BASE_URL + '/logout'
        })
        return req;
    },

    getEditRecords() {
        const req = request({
            method: 'get',
            url: BASE_URL + '/editrecord'
        })
        return req;
    },

    getDiff(title) {
        const req = request({
            method: 'get',
            url: BASE_URL + '/editrecord/diff',
            params: {
                title: title
            }
        })
        return req;
    },

    deleteArticle(title) {
        const req = request({
            method: 'delete',
            url: BASE_URL + '/article',
            params: {
                title: title
            }
        })
        return req;
    },

    acceptEdit(edit) {
        const req = request({
            method: 'post',
            url: BASE_URL + '/editrecord/accept',
            data: edit
        })
        return req;
    },

    findArticleByTitle(title) {
        const req = request({
            method: 'get',
            url: BASE_URL + '/article',
            params: {
                title: title
            }
        })
        return req;
    },

    listArticleTitles() {
        const req = request({
            method: 'get',
            url: BASE_URL + '/article/title',
        })
        return req;
    },

    uploadArticle(article) {
        const req = request({
            method: 'post',
            url: BASE_URL + '/article',
            data: article
        })
        return req;
    },

    listMessages() {
        const req = request({
            method: 'get',
            url: BASE_URL + '/mb',
        })
        return req;
    },

    submitMessage(message) {
        const req = request({
            method: 'post',
            url: BASE_URL + '/mb',
            data: message
        })
        return req;
    },

    replyMessage(reply) {
        const req = request({
            method: 'get',
            url: BASE_URL + '/mb/reply',
            params: {
                messageId: reply.messageId,
                to: reply.to,
                content: reply.content
            }
        })
        return req;
    },

    visualize(sub, n) {
        const req = request({
            method: 'get',
            url: BASE_URL + '/vis',
            params: {
                sub: sub,
                n: n
            }
        })
        return req;
    }



}